package com.example.注解和反射.reflection;

/**
 * 测试Class类的创建方式有哪些
 */
public class Test02 {
    public static void main(String[] args) throws ClassNotFoundException {
        Person student = new Student();
        System.out.println("这个人是:"+student.name);

        //方式一：通过对象获取
        Class c1 = student.getClass();
        System.out.println(c1.hashCode());

        //方式二：forname获取
        Class c2 = Class.forName("com.example.注解和反射.reflection.Student");
        System.out.println(c2.hashCode());

        //方式三：通过类名.class获取
        Class c3= Student.class;
        System.out.println(c3.hashCode());

        //方式四：基本内置数据类型包装类
        Class c4= Integer.TYPE;
        System.out.println(c4);

        //方式五：获取父类类型
        Class c5= c1.getSuperclass();
        System.out.println(c5);
    }
}

class Person{
    String name;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return super.toString();
    }
}

class Student extends Person{

    public Student() {
        this.name="学生";
    }
}

class Teacher extends Person{

    public Teacher() {
        this.name="老师";
    }
}
